package Date;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @description:
 * @author: cyy
 **/
public class calendar {
    public static void main(String[] args) {


    }

    /**
     *获取上一月
     */
    private static void getPreMOnth() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM");
        cal.add(cal.MONTH, -1);
        String Month = dft.format(cal.getTime());
        System.out.println("Month:"+Month);
    }

    /**
     * 获取当前时间年月
     */
    private static void getYearMonth() {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        String month = cal.get(Calendar.MONTH )+1 < 10 ? "0"+(cal.get(Calendar.MONTH )+1) : cal.get(Calendar.MONTH )+1+"";
        System.out.println("shitutuya:"+year + "-" +month);
    }

    /**
     *获取当前天的后一天
     */
    public static String getPreYearMonth(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH,+1);
        return sdf.format(cal.getTime());
    }

    /**
     *获取当前天的前十分钟
     */
    public static String getPreTenTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE,-10);
        return sdf.format(cal.getTime());
    }
}